<template>
    <div style="margin-bottom: 1.5rem">
        <div
            style="background: #FFDDBA;position: absolute;top:0;width: 100%;z-index: 99;"
            v-if="notice_text"
        >
            <div class="liMarquee">
                <img src="../images/toutiao.png" style="z-index: 9999;" />
                <div class="janros">
                    <div class="list">
                        <div class="cc rowup">
                            <MarqueeTips
                                :content="notice_text"
                                :speed="50"
                            ></MarqueeTips>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div style="position: relative;z-index: 1;">
            <div class="IndexBanner">
                <div class="banner_head">
                    <div class="swiper-container swiper-container1">
                        <div class="swiper-wrapper">
                            <div
                                class="swiper-slide"
                                v-for="imgs in bannerImgs"
                                :key="imgs"
                                @click="jumpLinkBanner(imgs.jump_link)"
                            >
                                <img :src="imgs.img_url" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <transition name="fade">
                <div v-if="grids.message">
                    <div class="userData">
                        <ul>
                            <li>
                                <p>{{ grids.message.user_balance }}</p>
                                <p>钱包</p>
                            </li>
                            <li>
                                <p>{{ grids.message.totay_money }}</p>
                                <p>今日</p>
                            </li>
                            <li>
                                <p>{{ grids.message.yesterday_money }}</p>
                                <p>昨日</p>
                            </li>
                        </ul>
                    </div>
                </div>
            </transition>

            <div style="height: 1.5rem;margin-bottom: .4rem;">
                <div class="workList">
                    <ul>
                        <li class="unread" @click="unreadLink()">
                            <img
                                src="../images/nav-icon1.png"
                                class="wokrListIcon"
                            />
                            <em v-if="unread">{{ unread }}</em>
                        </li>

                        <li
                            class="unread"
                            v-on:click="taskLink(1)"
                            v-if="is_greener"
                        >
                            <img
                                src="../images/nav-icon2.png"
                                class="wokrListIcon"
                            />
                            <em v-if="is_greener_num">{{ is_greener_num }}</em>
                        </li>
                        <li class="unread" v-on:click="tuijianfc()">
                            <img
                                src="../images/nav-icon.png"
                                class="wokrListIcon"
                            />
                            <em v-if="tuijian">{{ tuijian }}</em>
                        </li>
                        <li class="unread" v-on:click="privilegeTask(1)">
                            <img
                                src="../images/nav-icon3.png"
                                class="wokrListIcon"
                            />
                            <em v-if="returnNumber">{{ returnNumber }}</em>
                        </li>
                        <li @click="signInRes">
                            <img
                                src="../images/nav-icon4.png"
                                class="wokrListIcon"
                            />
                        </li>
                    </ul>
                </div>
            </div>

            <div class="invterfirends-ban">
                <!--<div class="fl_invter contentImg" id="invterFirends">-->
                <!--<router-link to="/task/Apprentice" style="width: 100%;height: 100%;display: block;"></router-link>-->
                <!--</div>-->
                <!--<div class="fr_invter contentImg" v-on:click="privilegeTask()">-->
                <!--<span class="fr_invter-img" v-if="grids"><img src="../images/fr_invter-img.png" alt="">Lv{{ grids.message.user_level }}</span>-->
                <!--</div>-->
                <!--<div class="balance" v-if="grids" @click="$toast('您近期的任务正确率评分 ' + user_work_count.score)"><strong>{{-->
                <!--user_work_count.score }}分</strong></div>-->
                <div>
                    <router-link to="/task/Apprentice"
                        ><img src="../images/zhong2.png" alt=""
                    /></router-link>
                    <a :href="domain + '/app_html/help_center.html'"
                        ><img src="../images/zhong1.png" alt=""
                    /></a>
                </div>
                <div>
                    <!--privilegeTask()-->
                    <img
                        src="../images/zhong3.png"
                        alt=""
                        v-on:click="alert_show()"
                    />
                </div>
            </div>

            <div v-if="models_table == 1">
                <div class="show_boxs" @click="hide_alert()"></div>
                <div class="model_alert">
                    <ul>
                        <li
                            v-for="tab in platforms_tab"
                            :key="tab"
                            @click.stop="privilegeTask(0, tab.platform_id)"
                        >
                            {{ tab.platform_name }}
                        </li>
                    </ul>
                </div>
            </div>

            <div class="platforms_tab">
                <ul>
                    <li
                        v-for="tab in platforms_tab"
                        :key="tab"
                        v-if="tab.platform_tag != 'tianmao'"
                        :class="{ on: platforms_tab_txt == tab.platform_tag }"
                        @click="
                            (platforms_tab_txt = tab.platform_tag),
                                (platforms_tab_id = tab.platform_id),
                                (grids.data = '')
                        "
                    >
                        {{ tab.platform_name }}
                    </li>
                </ul>
            </div>

            <div style="height: 90vw">
                <transition name="fade">
                    <div style="padding-bottom: 1.5rem" v-if="grids.data">
                        <div class="platformWorks clearfix" v-if="work_status">
                            <ul :class="{ on: !time }">
                                <li>
                                    <p>进行中</p>
                                    <span @click="submitMytask(1, '进行中任务')"
                                        >（{{ work_status_arr.going }}）</span
                                    >
                                </li>
                                <li>
                                    <p>待审核</p>
                                    <span @click="submitMytask(6, '待审核任务')"
                                        >（{{ work_status_arr.audit }}）</span
                                    >
                                </li>
                                <!-- <li v-if="platforms_tab_id == 1">
                                    <p>待审核</p>
                                    <span @click="submitMytask(6, '待审核任务')">（{{ tbworkAuditNumber }}）</span>
                                </li>
                                <li v-else-if="platforms_tab_id ==2">
                                    <p>待审核</p>
                                    <span @click="submitMytask(6, '待审核任务')">（{{ jdworkAuditNumber }}）</span>
                                </li>
                                <li v-else>
                                    <p>待审核</p>
                                    <span @click="submitMytask(6, '待审核任务')">（{{ pddworkAuditNumber }}）</span>
                                </li> -->
                                <li>
                                    <p>未通过</p>
                                    <span @click="submitMytask(5, '未通过任务')"
                                        >（{{
                                            work_status_arr.not_pass
                                        }}）</span
                                    >
                                </li>
                            </ul>
                            <div v-if="time">
                                <p>未通过任务请尽快提交</p>
                                <p v-if="time">{{ time }}后自动放弃</p>
                            </div>
                        </div>
                        <!--<div class="clearfix view-switches">-->
                        <!--<img src="@/images/wg-icon-1.png" alt="" class="fl">-->
                        <!--<img src="@/images/lb-icon-2.png" alt="" class="fr" @click="gridView = !gridView">-->
                        <!--</div>-->
                        <div class="grid-view">
                            <ul class="clearfix">
                                <li
                                    v-for="(task, index) in grids.data"
                                    @click="gridsUrl(task.type)"
                                    :key="index"
                                >
                                    <img :src="task.icon" alt="" class="fl" />
                                    <!--<h4>{{ task.name }}<span v-if="task.num || task.num == 0"> ({{ task.num }})</span></h4>-->
                                    <h4>{{ task.name }}</h4>
                                </li>
                            </ul>
                            <!--<div style="padding: 0 .2rem">-->
                            <!--<div @click="taskLink(2)" id="corss">-->
                            <!--<em class="fr"><i>50</i>个</em>-->
                            <!--<p><img src="@/images/huang.png" alt="">限时任务专属大厅 <span>领取限制放宽</span></p>-->
                            <!--</div>-->
                            <!--</div>-->
                        </div>
                        <!--<div class="game-task">-->
                        <!--<h3 class="clearfix"><img src="@/images/gameLogo.gif" class="los">试玩任务 <span class="fr">玩游戏也能赚佣金<img-->
                        <!--src="@/images/game-icon-right.png" alt="" class="ics" ></span></h3>-->
                        <!--</div>-->
                        <!-- <div class="returnData"><img src="../images/zdqd.png" alt="" @click="randomWork"></div> -->
                        <div class="timing-works" v-if="timingWorksList">
                            <div>
                                <h2>定时上新</h2>
                            </div>
                            <ul class="timing-works-list">
                                <li
                                    class="clearfix"
                                    v-for="task in timingWorksList"
                                    :key="task"
                                >
                                    <div class="clearfix">
                                        <img
                                            :src="task.image.url"
                                            alt=""
                                            class="fl"
                                            v-if="
                                                task.image.url.indexOf(
                                                    'http'
                                                ) != -1
                                            "
                                        />
                                        <img
                                            :src="
                                                qiniu_domain_url +
                                                    task.image.url
                                            "
                                            class="fl"
                                            v-else
                                        />

                                        <div style="padding-left: .3rem">
                                            <h3>
                                                {{ task.goods.goods_title }}
                                            </h3>
                                            <p v-if="task.timingTime">
                                                <span>{{
                                                    task.timingTime
                                                }}</span
                                                >后上新
                                            </p>
                                            <p>请到任务大厅领取</p>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="timing-works" v-if="preheatList">
                            <div>
                                <h2>任务预热</h2>
                            </div>
                            <ul class="timing-works-list">
                                <li
                                    class="clearfix"
                                    v-for="task in preheatList"
                                    :key="task"
                                    @click="gridsUrl(0, task.list.platform_id)"
                                >
                                    <div class="clearfix">
                                        <img
                                            :src="task.list.image"
                                            alt=""
                                            class="fl"
                                            v-if="
                                                task.list.image.indexOf(
                                                    'http'
                                                ) != -1
                                            "
                                        />
                                        <img
                                            :src="
                                                qiniu_domain_url +
                                                    task.list.image
                                            "
                                            class="fl"
                                            v-else
                                        />
                                        <div class="work_hotRight fl">
                                            <h3>{{ task.list.items }}</h3>
                                            <p>
                                                <span v-if="task.timingTime">{{
                                                    task.timingTime
                                                }}</span
                                                >后上新
                                            </p>
                                            <p>请到任务大厅领取</p>
                                        </div>
                                    </div>
                                    <span v-if="task.list.platform_id == 1"
                                        >淘宝</span
                                    >
                                    <span v-else-if="task.list.platform_id == 2"
                                        >京东</span
                                    >
                                    <span v-else-if="task.list.platform_id == 3"
                                        >拼多多</span
                                    >
                                </li>
                            </ul>
                        </div>
                        <!--<div class="botmImgs-kgts"  v-if="preheatList">-->
                        <!--<img src="../images/kgts.png" />-->
                        <!--</div>-->
                    </div>
                </transition>
            </div>
            <!--任务预热-->
        </div>
        <!-- 首页弹窗 -->
        <div class="tc-img" v-if="tcImg" @click="tcImg = false">
            <img :src="tcImg" alt="" />
        </div>
        <!-- 长连接消息 -->
        <polling />
        <!-- 提醒回访任务 -->
        <!--<div class="returnData" v-if="returnNumber" style="font-size: .3rem"><img src="../images/logoGif.gif" alt="">您有新的回访任务-->
        <!--<span @click="returnWork">立即领取</span></div>-->
        <!--<div class="returnData" v-else><img src="../images/logoGif.gif" alt="">不想找？<span-->
        <!--@click="randomWork">抢一个</span></div>-->

        <!-- 底部切换 -->
        <barTab />
        <!-- <loading :loading="loadingTrue"/> -->
    </div>
</template>

<script>
import api from "../utils/api";
import { domain } from "../utils/api";
import MarqueeTips from "vue-marquee-tips";
import Polling from "@/components/components/polling";
import barTab from "@/components/components/barTabBottom";
import loading from "@/components/components/loading";
import axios from "axios";
import { MessageBox } from "mint-ui";

export default {
    name: "Index",
    components: {
        MarqueeTips,
        Polling,
        barTab,
        loading
    },
    data() {
        return {
            domain: "",
            type: 0,
            tasks: [],
            consumer_id: 0,
            notice_text: "",
            bannerImgs: [],
            position: { x: 0, y: 0 },
            nx: "",
            ny: "",
            dx: "",
            dy: "",
            xPum: "",
            yPum: "",
            is_greener: false,
            logina: false,
            qiniu_domain: "",
            tjimg: false,
            endTime: false,
            time: false,
            unread: false,
            middleCarousel: false,
            // refreshActive: false,
            flag: false,
            randomWorkShow: true,
            flagShow: false,
            tuijian: false,
            returnNumber: false,
            consumersTab: false,
            tcImg: false,
            show: true,
            domin: localStorage.getItem("domin"),
            is_sign: true,
            activity: false,
            // gridView: true,
            newbies: true,
            grids: false,
            // credit_multiple: false, // 推荐积分
            // finish_work_credit: false, // 积分
            lottery_min_recommend_get: "",
            lottery_min_recommend_get_number: "",
            user_work_count: [],
            timingWorksList: false,
            timingTimeVal: null,
            preheatTimeVal: null,
            qiniu_domain_url: "https://wyrq-2.oss-cn-shanghai.aliyuncs.com/",
            platforms_tab: [],
            platforms_tab_id: "",
            platforms_tab_txt: "",
            work_status_arr: [],
            work_status_time: false,
            is_greener_num: "",
            tcTrues: this.$parent.$data.tcTrue,
            preheatList: false, //任务预热
            models_table: 0
            // tbworkAuditNumber:0,
            // jdworkAuditNumber:0,
            // pddworkAuditNumber:0,
            // loadingTrue: false
        };
    },
    async created() {
        this.domain = domain;
        //平台待审核任务数量
        // let tbworkAuditNumb = localStorage.getItem("tbworkAuditNumber");
        // if(tbworkAuditNumb != 0 && tbworkAuditNumb != null){
        //     this.tbworkAuditNumber = tbworkAuditNumb;
        // }
        // let jdworkAuditNumb = localStorage.getItem("jdworkAuditNumber");
        // if(jdworkAuditNumb != 0 && jdworkAuditNumb != null){
        //     this.jdworkAuditNumber = jdworkAuditNumb;
        // }
        // let pddworkAuditNumb = localStorage.getItem("pddworkAuditNumber");
        // if(pddworkAuditNumb != 0 && pddworkAuditNumb != null){
        //     this.pddworkAuditNumber = pddworkAuditNumb;
        // }

        // if(window.location.protocol.indexOf('https') != -1 || window.location.href.indexOf('192.168.0.165:8012') != -1){
        //
        // }else {
        //     window.location.href="https://testh5.woyaorenqi.com/";
        // }
        var that = this;
        // that.loadingTrue = true
        if (localStorage.getItem("consumersId")) {
            this.consumer_id = localStorage.getItem("consumersId");
        }
        localStorage.setItem("bartabInx", 1);

        //平台tab
        await api.request("/platforms", "get", {}).then(function(res) {
            that.platforms_tab = res.data.data;
            for (let i in res.data.data) {
                if (res.data.data[i].platform_tag == "taobao") {
                    that.platforms_tab_txt = res.data.data[i].platform_tag;
                    that.platforms_tab_id = res.data.data[i].platform_id;
                }
            }
        });
        // 通知
        await api.request("/notice", "get", {}).then(resp => {
            var lis = "";
            for (let notice in resp.data.data) {
                lis += resp.data.data[notice].content + "      ";
            }
            this.bannerImgs = resp.data.message;
            this.notice_text = lis;
            this.$nextTick(() => {
                new Swiper(".swiper-container1", {
                    autoplay: 3000
                });
            });
        });

        // 萌新攻略
        this.newbies = !!localStorage.getItem("newbiesExpand");
        await api.request("/InvalidConsumers", "get", {}).then(resp => {
            var data = resp.data.data;
            var datas = [];
            for (let i in data) {
                if (data[i].status.val == 2) {
                    datas.push(data[i]);
                }
            }
            if (datas.length >= 1 && this.tcTrues) {
                MessageBox.confirm("审核未通过，请点击未通过修改提交")
                    .then(a => {
                        let platform_tag = datas[0].platform.platform_tag;
                        let title = "淘宝";
                        if (platform_tag == "taobao") {
                            title = "淘宝";
                        } else if (platform_tag == "jd") {
                            title = "京东";
                        } else if (platform_tag == "pinduoduo") {
                            title = "拼多多";
                        }
                        that.$router.push({
                            path: "/task/bindingTao",
                            query: {
                                platform_id: datas[0].platform_id,
                                title: title,
                                platform_tag: datas[0].platform.platform_tag
                            }
                        });
                    })
                    .catch(() => {});
            }
        });
    },
    methods: {
        //抢任务
        // async randomWork() {
        //     if (this.randomWorkShow) {
        //         this.randomWorkShow = false;
        //         setTimeout(() => {
        //             this.randomWorkShow = true;
        //         }, 2000)
        //         let param = {
        //             consumer_id: this.consumer_id
        //         }
        //         let resp = await api.request('/works/randomWork', 'post', param)
        //         let id = resp.data.data.work_user_id;
        //         window.AndroidWebView.PictureCallback(`${this.domin}task/detail/${id}`, '任务详情');

        //     } else {
        //         this.$toast('手速太快请稍后重试')
        //     }
        // },

        alert_show() {
            this.models_table = 1;
        },
        hide_alert() {
            this.models_table = 0;
        },
        // async workAuditNum() {
        //     var that = this;
        //      await api.request('/workAuditNum', 'get', {platform_id: this.platforms_tab_id}).then(function (res) {
        //         that.workAuditNumber = res.data.data.audit;
        //         console.log(that.workAuditNumber)
        //      })
        // },
        async submitMytask(status = 0, name = "全部任务") {
            this.$router.push({
                path: `/task/my_task_list/${status}`,
                query: {
                    status: status,
                    name: name,
                    platform_id: this.platforms_tab_id
                }
            });
            // window.AndroidWebView.PictureCallback(`${this.domin}task/my_task_list/${status}`,name);
        },
        async work_status() {
            var that = this;
            await api
                .request("/index_work_status", "get", {
                    platform_id: this.platforms_tab_id
                })
                .then(function(res) {
                    that.work_status_arr = res.data.data;
                    if (res.data.data.last_expire) {
                        that.endTime = new Date(
                            parseInt(res.data.data.last_expire * 1000)
                        ).toLocaleString("chinese", { hour12: false });
                        that.work_status_time = setInterval(() => {
                            if (that.flag === true) {
                                clearInterval(that.work_status_time);
                                that.flagShow = false;
                            } else {
                                that.flagShow = true;
                            }
                            that.timeDown();
                        }, 1000);
                    } else {
                        clearInterval(that.work_status_time);
                        that.time = "";
                        that.endTime = "";
                    }
                });
        },
        taskLink(index) {
            if (this.consumersTab.length == 0) {
                this.$toast("请先去个人中心绑定任务号");
                // this.loadingTrue = false
                return false;
            }
            this.$router.push({
                path: `/task/list/${index}?platform_id=${this.platforms_tab_id}`
            });
        },
        async privilegeTask(inx = 0, platforms_id) {
            if (platforms_id) {
                this.platforms_tab_id = platforms_id;
            }
            let consumers = await api
                .request("/consumers/normal", "get", {
                    platform_id: this.platforms_tab_id
                })
                .then(res => {
                    this.consumersTab = res.data.data;
                    if (this.consumersTab.length == 0) {
                        return false;
                    }
                    if (this.returnNumber <= 0 && inx == 1) {
                        this.$toast("暂无回访任务");
                        return false;
                    }
                    this.$router.push({
                        path: `/task/privilege?platform_id=${this.platforms_tab_id}`
                    });
                });
        },
        //老的跳转 跳转到特权任务
        // async tuijianfc() {
        //     let that = this;
        //     var url = "/privilege";
        //     let params = {
        //         consumer_id: this.consumer_id,
        //         platform_id: this.platform_id,
        //         type: 8,
        //         page: 0
        //     };
        //     await api.request(url, "get", params).then(resp => {
        //         let a = resp.data.data.length;
        //         if (a <= 0) {
        //             that.$toast("暂无回访任务");
        //         } else {
        //             localStorage.setItem("tjzdyrw", 1);
        //             that.$router.push({
        //                 path: `/task/privilege?platform_id=${that.platforms_tab_id}`
        //             });
        //         }
        //     });
        // },

        async tuijianfc() {
            let type = 8;
            let platform_id = this.platform_id;
            this.gridsUrl(type, platform_id);
        },
        // 新手随机领取
        // async randomWork() {
        //     if (this.randomWorkShow) {
        //         this.randomWorkShow = false;
        //         setTimeout(() => {
        //             this.randomWorkShow = true;
        //         }, 2000)
        //         let param = {
        //             consumer_id: this.consumer_id
        //         }
        //         let resp = await api.request('/works/randomWork', 'post', param)
        //         let id = resp.data.data.work_user_id;
        //         this.$router.push({
        //             path: `task/detail/${id}`
        //         })
        //     } else {
        //         this.$toast('手速太快请稍后重试')
        //     }
        // },
        unreadLink() {
            this.$router.push({
                path: `/task/message`
            });
        },
        async returnWork() {
            if (this.returnNumber) {
                let param = {
                    consumer_id: this.consumer_id
                };
                let resp = await api.request(
                    "/works/returnRandomWork",
                    "post",
                    param
                );
                let id = resp.data.data.work_user_id;
                this.$router.push({
                    path: `task/detail/${id}`
                });
            } else {
                this.$toast("暂无回访任务");
            }
        },
        jumpLinkBanner(url) {
            if (url) {
                let urlBanner = "";
                urlBanner = url + "?token=" + localStorage.getItem("token");
                window.location = urlBanner;
            }
        },
        async notice() {
            // 分数
            await api.request("/user_work_count", "get", {}).then(resp => {
                this.user_work_count = resp.data.data;
            });
            //我的消息是否有未读
            await api
                .request("/user-notice/unread-count", "get", {})
                .then(resp => {
                    this.unread = resp.data.data;
                });
            //推荐任务数量
            var url = "/privilege";
            let params = {
                consumer_id: this.consumer_id,
                platform_id: this.platform_id,
                type: 8,
                page: 0
            };
            await api.request(url, "get", params).then(resp => {
                this.tuijian = resp.data.data.length;
            });
            // 回访任务数量
            await api
                .request("/returnNumber", "get", {
                    consumer_id: this.consumer_id,
                    platform_id: this.platforms_tab_id
                })
                .then(resp => {
                    this.returnNumber = resp.data.data;
                    this.is_greener_num = resp.data.message;
                });
            // //首页中部轮播
            // await api.request('/notice', 'get', {type: 5}).then((resp) => {
            //     this.middleCarousel = resp.data.message
            //     if (this.newbies) {
            //         this.$nextTick(() => {
            //             new Swiper('.swiper-container2', {})
            //         })
            //     }
            // })
            // //计时任务发布时间
            await api
                .request("/preheat", "get", { consumer_id: this.consumer_id })
                .then(resp => {
                    if (resp.data.message != 2 && resp.data.data != "") {
                        this.preheatList = resp.data.data;
                        var _that = this;
                        clearInterval(_that.preheatTimeVal);
                        _that.preheatTimeVal = setInterval(function() {
                            _that.preheatTiming_val();
                        }, 1000);
                    }
                });
        },
        // 定时任务返回日期算法
        preheatTiming_task(leftTime) {
            let time = "";
            let d = parseInt(leftTime / (24 * 60 * 60));
            let h = this.formate(parseInt((leftTime / (60 * 60)) % 24));
            let m = this.formate(parseInt((leftTime / 60) % 60));
            let s = this.formate(parseInt(leftTime % 60));
            if (leftTime <= 1) {
                this.timingTime = false;
                return false;
            }
            d != 0 ? (time += d + "天") : "";
            h != 0 ? (time += h + "小时") : "";
            m != 0 ? (time += m + "分") : "";
            return time + s + "秒";
        },
        // 循环输出剩余时间
        preheatTiming_val() {
            var _that = this;
            for (var i in _that.preheatList) {
                var tims = this.preheatTiming_true(
                    _that.preheatList[i].list.start_time,
                    _that.preheatList[i].list.mktime
                );
                _that.preheatList[i].list.mktime++;

                if (tims) {
                    _that.$set(
                        _that.preheatList[i],
                        "timingTime",
                        _that.preheatTiming_task(tims)
                    );
                } else {
                    _that.$set(_that.preheatList[i], "timingTime", "");
                }
            }
        },
        // 定时任务判断
        preheatTiming_true(start_time, mktime) {
            var set = parseInt(start_time) - parseInt(mktime);

            if (set <= 0) {
                return false;
            } else {
                return set;
            }
        },
        async common() {
            // 公共参数
            let resp = await api.request("/common", "get", {});
            localStorage.setItem("TIME", resp.data.data.auto_time);
            let datas = resp.data.data;
            // 热门活动
            localStorage.setItem("activity", datas.activity);
            localStorage.setItem("qq_flock", datas.qq_flock);
            localStorage.setItem(
                "lottery_min_recommend_get",
                datas.lottery_min_recommend_get
            );
            localStorage.setItem(
                "lottery_min_recommend_get_number",
                datas.lottery_min_recommend_get_number
            );
            this.lottery_min_recommend_get = datas.lottery_min_recommend_get;
            this.lottery_min_recommend_get_number =
                datas.lottery_min_recommend_get_number;
            // 普通任务积分
            // this.finish_work_credit = datas.finish_work_credit
            localStorage.setItem(
                "finish_work_credit",
                datas.finish_work_credit
            );
            // 推荐任务积分
            // this.credit_multiple = datas.credit_multiple
            localStorage.setItem("credit_multiple", datas.credit_multiple);
            this.activity = datas.activity;
            if (datas.is_greener) {
                this.newbies = true;
            } else {
                this.newbies = false;
            }
            this.is_greener = datas.is_greener;
            this.is_sign = datas.is_sign;
            localStorage.setItem(
                "qiniu_domain",
                datas.service_qiniu_domain + "/"
            );
            this.qiniu_domain = datas.service_qiniu_domain + "/";
        },
        BeginnersJump(inx) {
            // 0 登陆页面 1 绑定买号 2 绑定微信页面 3 帮助页面 4 任务列表 5 邀请好友
            window.AndroidWebView.consumers(Number(inx));
        },
        formate(time) {
            if (time >= 10) {
                return time;
            } else {
                return `0${time}`;
            }
        },
        async consumers() {
            let consumers = await api.request("/consumers/normal", "get", {
                platform_id: this.platforms_tab_id
            });
            this.consumersTab = consumers.data.data;
        },
        async uploadImg() {
            // 是否存储买号
            var consumers = await api.request("/consumers/normal", "get", {
                platform_id: this.platforms_tab_id
            });

            if (consumers.data.data.length == 0) {
                // this.consumers()
                this.$toast("请先去个人中心绑定任务号");
                // this.loadingTrue = false
                // return false;
            } else {
                this.consumer_id = consumers.data.data[0].consumer_id;
            }
            this.consumersTab = consumers.data.data;
            // 存储买号 默认为一
            if (consumers.data.data && !localStorage.getItem("consumersId")) {
                localStorage.setItem(
                    "consumersId",
                    consumers.data.data[0].consumer_id
                );
                this.consumer_id = consumers.data.data[0].consumer_id;
            }
            await api
                .request("/grids", "get", {
                    platform_id: this.platforms_tab_id,
                    consumer_id: this.consumer_id
                })
                .then(resp => {
                    this.grids = resp.data;
                    // this.loadingTrue = false
                })
                .catch(resp => {
                    if (resp.error.indexOf("请选择默认任务号") != -1) {
                        localStorage.setItem(
                            "consumersId",
                            this.consumersTab[0].consumer_id
                        );
                        this.consumer_id = this.consumersTab[0].consumer_id;
                    }
                    // this.loadingTrue = false
                });
            // // 首页弹窗
            // await api.request('/notice', 'get', {type: 4}).then((resp) => {
            //     if (resp.data.message.length >= 1) {
            //         this.$nextTick(() => {
            //             this.tcImg = resp.data.message[0].img_url
            //         })
            //     }
            // })
        },
        async signInRes() {
            this.is_sign = true;
            await api.request("/signIn", "post", {}).then(res => {
                this.$toast(res.data.message + "获得奖励" + res.data.data);
            });
        },
        formatStr(str) {
            var head = str.substring(0, 5, str.length);
            var last = str.substring(5, str.length);
            return head + "*".repeat(last.length);
        },
        async gridsUrl(type, platform_id) {
            if (platform_id) {
                this.platforms_tab_id = platform_id;
            }
            var consumers = await api.request("/consumers/normal", "get", {
                platform_id: this.platforms_tab_id
            });

            if (consumers.data.data.length == 0) {
                this.$toast("请先去个人中心绑定任务号");
                // this.loadingTrue = false
                return false;
            } else {
                this.$router.push({
                    // path: `/task/privilege?platform_id=${this.platforms_tab_id}`
                    path: `task/list/${0}?type=${type}&platform_id=${
                        this.platforms_tab_id
                    }&model=1`
                });
            }
        },
        timeDown() {
            const endTime = new Date(this.endTime);
            const nowTime = new Date();
            let time = "";
            let leftTime = parseInt(
                (endTime.getTime() - nowTime.getTime()) / 1000
            );
            let d = parseInt(leftTime / (24 * 60 * 60));
            let h = this.formate(parseInt((leftTime / (60 * 60)) % 24));
            let m = this.formate(parseInt((leftTime / 60) % 60));
            let s = this.formate(parseInt(leftTime % 60));
            if (leftTime <= 0) {
                this.flag = true;
                return false;
            }
            d != 0 ? (time += d + "天") : "";
            h != 0 ? (time += h + "小时") : "";
            m != 0 ? (time += m + "分") : "";
            this.time = time + s + "秒";
        },
        // 定时上新
        async timingWorksFun() {
            var _that = this;
            await api.request("/timingWorks", "get", {}).then(res => {
                if (res.data.data != "") {
                    _that.timingWorksList = res.data.data;
                } else {
                    return false;
                }
                clearInterval(_that.timingTimeVal);
                _that.timingTimeVal = setInterval(function() {
                    _that.timing_val(Date.parse(new Date()) / 1000);
                }, 1000);
            });
        },
        // 定时任务返回日期算法
        timing_task(leftTime) {
            let time = "";
            let d = parseInt(leftTime / (24 * 60 * 60));
            let h = this.formate(parseInt((leftTime / (60 * 60)) % 24));
            let m = this.formate(parseInt((leftTime / 60) % 60));
            let s = this.formate(parseInt(leftTime % 60));

            d != 0 ? (time += d + "天") : "";
            h != 0 ? (time += h + "小时") : "";
            m != 0 ? (time += m + "分") : "";
            return time + s + "秒";
        },
        // 循环输出剩余时间
        timing_val(timestamp) {
            var _that = this;
            for (var i in _that.timingWorksList) {
                var tims = this.timing_true(
                    _that.timingWorksList[i].start_timing,
                    timestamp
                );
                if (tims) {
                    _that.$set(
                        _that.timingWorksList[i],
                        "timingTime",
                        _that.timing_task(tims)
                    );
                }
            }
        },
        timing_true(start_time, timestamp) {
            var set = parseInt(start_time) - timestamp;
            if (set <= 0) {
                return false;
            } else {
                return set;
            }
        },
        async upgrade() {
            var _that = this;
            await api.request("/upgrade", "get", {}).then(res => {
                if (res.data.data.is_upgrade == "1") {
                    window.location.href = window.location.href;
                    localStorage.setItem("upgradeStatus", 1);
                }
            });
        }
        // async anumber(){
        //     console.log("coolcool滴！")
        //     let that = this;
        //     await api.request('/workAuditNum', 'get', {}).then(function (res) {
        //         that.tbworkAuditNumber = res.data.data.taobao.num;
        //         that.jdworkAuditNumber = res.data.data.jingdong.num;
        //         that.pddworkAuditNumber = res.data.data.pingduoduo.num;
        //     })
        // },
    },
    mounted() {
        // 待审核任务数量
        // let anumber = localStorage.getItem("anumber");
        // if(anumber != 1){
        //     this.anumber();
        //     localStorage.setItem("anumber",1);
        // }

        if (
            localStorage.getItem("upgradeStatus") != 1 ||
            !localStorage.getItem("upgradeStatus")
        ) {
            this.upgrade();
        }
        this.common();
        // this.uploadImg()
        this.timingWorksFun();
        this.notice();
    },
    watch: {
        consumer_id(newValue) {
            localStorage.setItem("consumersId", newValue);
            // this.refresh()
        },
        newbies(newbies) {
            if (newbies && this.middleCarousel) {
                this.$nextTick(() => {
                    new Swiper(".swiper-container2", {});
                });
            }
            if (newbies) {
                localStorage.setItem("newbiesExpand", 1);
            } else {
                localStorage.removeItem("newbiesExpand");
            }
        },
        async platforms_tab_id(platform) {
            this.uploadImg();
            this.work_status();
        }
    }
};
</script>

<style scoped>
.model_alert {
    position: fixed;
    top: 50%;
    width: 9rem;
    height: 7.5rem;
    left: 50%;
    z-index: 99999;
    margin-left: -4.5rem;
    margin-top: -4.55rem;
    -webkit-border-radius: 0.3rem;
    -moz-border-radius: 0.3rem;
    border-radius: 0.3rem;
    background-color: #fff;
    /* background: url("../images/bgs.png") no-repeat; */
    background-size: cover;
}
.model_alert ul {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: center;
}
.model_alert ul li {
    font-size: 0.45rem;
    line-height: 1.2rem;
    border: 1px solid #ff8e0c;
    width: 7.5rem;
    text-align: center;
    border-radius: 0.2rem;
    color: #ff7542;
    background: #fff;
    margin-top: 0.5rem;
}
.model_alert ul li:nth-child(1) {
    margin-top: 0;
}
.show_boxs {
    position: fixed;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 9999;
}
@keyframes rowup {
    0% {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
    100% {
        -webkit-transform: translate3d(-100%, 0, 0);
        transform: translate3d(-100%, 0, 0);
    }
}

.list {
    position: relative;
    overflow: hidden;
    font-size: 0.28rem;
}

.list .item {
    width: 10000px;
}

.list .item span {
    display: inline-block;
}

.list .item span {
    -webkit-animation: 10s rowup linear infinite normal;
    animation: 10s rowup linear infinite normal;
    position: relative;
}

#beginner .swiper-slide {
    height: 2.2rem;
}

#beginner .banner-f2 {
    width: 100%;
}

+ #beginner .banner-f2 img {
    height: 100%;
    display: block;
    background: #fff;
}

.consumerBody select {
    background: transparent;
    border: 0;
    -webkit-border-radius: 0.1rem;
    -moz-border-radius: 0.1rem;
    border-radius: 0.1rem;
    outline: none;
    width: 2.4rem;
    color: #a2d0fc;
    position: absolute;
    line-height: 0.8rem;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

.tc-img {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.7);
}

.tc-img img {
    max-width: 90%;
    display: block;
    margin: 0 auto;
    margin-top: 20%;
}

#signIn {
    position: absolute;
    top: -0.1rem;
    right: -0.1rem;
    width: 0.9rem;
    height: 0.9rem;
    -webkit-box-shadow: 0 0 0.2rem #0ca3f9;
    box-shadow: 0 0 0.2rem #0ca3f9;
    border-radius: 50%;
    z-index: 99;
    background: #fff;
    padding-top: 0;
}

#signIn img {
    width: 0.6rem;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -0.3rem;
    margin-top: -0.25rem;
}

/* .returnData span {
        color: #FF9815;
        margin-left: .3rem;
    }

    .returnData img {
        width: 1rem;
        top: -0.65rem;
        left: .5rem;
        position: absolute;

    } */

.is_greenerAnimate {
    animation: is_greenerAnimate 1.5s infinite;
}

@keyframes is_greenerAnimate {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

.balance {
    animation: bounce-in 0.5s;
}

@keyframes bounce-in {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.5);
    }
    100% {
        transform: scale(1);
    }
}

#corss p {
    font-weight: 600;
    color: #6c5b27;
}

#corss p img {
    width: 0.9rem;
    display: inline-block;
    vertical-align: middle;
    margin-top: -0.3rem;
    margin-right: 0.3rem;
}

#corss .fr i {
    color: #d8b463;
    font-weight: 600;
    margin-right: 0.1rem;
}

#corss p span {
    font-size: 0.4rem;
    font-weight: 400;
    color: #43362b;
}
.kefu_s img {
    width: auto;
    height: 1rem;
}
.kefu_s {
    position: fixed;
    bottom: 2rem;
    right: 0.5rem;
}
.returnData {
    width: 5rem;
    height: 1.5rem;
    /* background: rgba(255, 255, 255, .9); */
    position: fixed;
    bottom: 1.65rem;
    left: 50%;
    margin-left: -2.5rem;
    /* padding: .15rem .3rem; */
    /* border-radius: .2rem; */
    /* color: #000; */
    z-index: 9999;
    /* font-weight: 600; */
    /* font-size: .4rem; */
    /* padding-left: 1.8rem; */
    text-align: center;
    line-height: 1.5rem;
    /* box-shadow: 0 0 0.2rem #333; */
}

/* .returnData span {
        color: #000;
        margin-left: .3rem;
    } */

.returnData img {
    width: 5rem;
    height: 1.5rem;
    /* top: -1.45rem;
        left: .5rem;
        position: absolute; */
}
</style>
